package com.harmonk.firstscene.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import androidx.room.Delete
import androidx.room.OnConflictStrategy
import com.harmonk.firstscene.db.entity.EventNote
import kotlinx.coroutines.flow.Flow

@Dao
interface EventNoteDao {
    @Query("SELECT * FROM event_notes WHERE eventNoteId = :id")
    suspend fun getTrafficNoteById(id: Long): EventNote

    @Query("SELECT * FROM event_notes WHERE eventId = :eventId ORDER BY timestamp ASC")
    fun getTrafficNotesByEventId(eventId: Long): Flow<List<EventNote>>

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insertTrafficNote(eventNote: EventNote): Long

    @Update
    suspend fun updateTrafficNote(eventNote: EventNote)

    @Delete
    suspend fun deleteTrafficNote(eventNote: EventNote)
    
    @Query("DELETE FROM event_notes WHERE eventId = :eventId")
    suspend fun deleteTrafficNotesByEventId(eventId: Long): Int
}